import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mokeng/widgets/get_view_keep_alive.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'logic.dart';

class WtbView extends GetViewKeepAlive<WtbController> {
  WtbView({super.key}) {
    Get.put(WtbController());
  }

  Widget buildCtn(WtbController controller) {
    return ListView.separated(
      padding: const EdgeInsets.only(left: 5, right: 5),
      itemBuilder: (c, i) => SizedBox(
        height: 100.0,
        child: Card(
          margin: const EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
          child: Center(
            child: Text(controller.data[i]),
          ),
        ),
      ),
      separatorBuilder: (context, index) {
        return Container(
          height: 0.5,
          color: Colors.greenAccent,
        );
      },
      itemCount: controller.data.length,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Obx(() => SmartRefresher(
          controller: controller.refreshController,
          enablePullUp: true,
          physics: const BouncingScrollPhysics(),
          footer: const ClassicFooter(
            loadStyle: LoadStyle.ShowWhenLoading,
            completeDuration: Duration(milliseconds: 500),
          ),
          onRefresh: controller.onRefresh,
          onLoading: controller.onLoading,
          child: buildCtn(controller),
        ));
  }
}
